<template>
  <div>
    <input
      v-if="isShow"
      ref="input"
      type="text"
      autofocus
      placeholder="请输入要搜索的关键字"
    />
    <button v-else @click="btn">点击搜索</button>
  </div>
</template>

<script>
// dom.focus() 获取焦点
export default {
  data() {
    return {
      isShow: false,
    }
  },
  methods: {
    btn() {
      this.isShow = !this.isShow
      this.$nextTick(() => {
        this.$refs.input.focus()
      })
    },
  },
}
</script>

<style></style>
